<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Dress extends FOX_Controller {

	function __construct ()
	{
		parent::__construct();
		$this->load->model('dress_m');
		$this->load->model('member_m');
		$this->load->library('form_validation');
		$this->config->load('userset');		
	}
	
	public function dress(){
		$user_id = $this->session->userdata('user_id');
	    $dress_id = $this->input->post('dress_id');
	    $dress=$this->member_m->get_address_by_uid($user_id);
	    if($user_id && $dress){
	    	$data1['dress_type']=0;
	    	$result = $this->member_m->change_dress_by_user_id($user_id,$data1);
	    	if($result){
	    		$data2['dress_type'] = 1;
        		$results = $this->member_m->change_dress_type($dress_id,$data2);
        		if($results){
        			$msg['info'] = "修改默认地址成功";
		         	$msg['status'] = 1;
		         	$msg['dress_id'] = $results['dress_id'];
		            echo json_encode($msg);
        		}else{
			    	$msg['status'] = 0;
			    	$msg['dress_id'] = $results['dress_id'];
		            echo json_encode($msg);
		    	}
        		
		    }
	    	
	    }
	}
	//删除收货地址
	public function del_dress(){
		$user_id = $this->session->userdata('user_id');
	    $dress_id = $this->input->post('dress_id');
	    if($user_id){
	    	$result = $this->dress_m->del_user_dress_by_id($dress_id,$user_id);
	    	if($result){
	    		$msg['info'] = "删除地址成功";
		        $msg['status'] = 1;
		        echo json_encode($msg);
	    	}else{
	    		$msg['info'] = "删除地址失败";
		        $msg['status'] = 0;
		        echo json_encode($msg);
	    	}
	    }
	}
	
}
